package com.hackerrank.challenges.ukandus2;

import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		in.nextLine();
		String w[][] = new String[N][];
		for(int i = 0; i < N; i++)
			w[i] = in.nextLine().split("\\s+");
		int T = in.nextInt();
		in.nextLine();
		for(int i = 0; i < T; i++) {
			String UK = in.nextLine(), US = UK.replaceAll("our", "or");
			int c = 0;
			for(int j = 0; j < N; j++)
				for(int k = 0; k < w[j].length; k++)
					if(w[j][k].equalsIgnoreCase(UK) || w[j][k].equalsIgnoreCase(US))
						c++;
			System.out.println(c);
		}
	}
}
